﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model Equipment
@{
    //ViewBag.Title = "价格核算";
    //var operationName = ViewBag.OperationName;
    //var operationTime = ViewBag.OperationTime;
    var equipmentName = ViewBag.EquipmentName;
    var techTypeList = ViewBag.TechTypeList as List<TechType>;
}
<section class="content-header">
    <h1>
        设备维护
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("Equipment", "Technology")">设备维护</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                <form class="form-horizontal" id="frmedit" action="@Url.Action("AddOrUpdateTechType", "Technology")" method="post">
                    <div class="box-body">

                        <div class="form-group col-md-6">
                            <label class="col-sm-3 control-label">设备名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="equipmentName" name="equipmentName" value="@equipmentName" data-des="设备名称" required />
                            </div>
                        </div>
                        <div class="form-group col-md-12" style="height: 1px;"></div>
                        @*<input type="hidden" id="modalData" value="@techTypeList" readonly="readonly">*@
                        <div id="all-content">
                            @if (techTypeList == null)
                            {
                                <input type="hidden" id="sign" name="sign" value="-1" />
                                <input type="hidden" id="EqId" name="EqId" value="@Model.Id" />
                                for (int i = 1; i < 6; i++)
                                {
                                    <div class="json-content">
                                        <div class="form-group col-md-6">
                                            @*<label class="col-sm-3 control-label">@i 类</label>*@
                                            <label class="col-sm-3 control-label">类别名称</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="TechTypeName" name="TechTypeName" value="@i 类" />
                                                <input type="hidden" id="TechTypeId" name="TechTypeId" value="@i"/>
                                                <input type="hidden" id="Id" name="Id" value="0"/>
                                                <input type="hidden" id="EquipmentId" name="EquipmentId" value="@Model.Id"/>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="WasteW" name="WasteW" value="" data-des="浪费比" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">设备产量/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="MinuteNum" name="MinuteNum" value="" data-des="设备产量/分钟" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">检验产量/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="ExamineNum" name="ExamineNum" value="" data-des="检验产量/分钟" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                    </div>
                                }
                            }
                            @if (techTypeList != null && techTypeList.Count != 0)
                            {
                                <input type="hidden" id="EqId" name="EqId" value="@Model.Id" />
                                <input type="hidden" id="sign" name="sign" value="1" />
                                for (int i = 1; i < 6; i++)
                                {
                                    <div class="json-content">
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">类别名称</label>
                                            <div class="col-sm-9">
                                                <input type="hidden" id="TechTypeId" name="TechTypeId" value="@i"/>
                                                <input type="text" class="form-control" id="TechTypeName" name="TechTypeName" value="@techTypeList[i-1].TechTypeName" />
                                                <input type="hidden" id="Id" name="Id" value="@techTypeList[i-1].Id" />
                                                <input type="hidden" id="EquipmentId" name="EquipmentId" value="@Model.Id" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="WasteW" name="WasteW" value="@techTypeList[i-1].WasteW" data-des="浪费比" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">设备产量/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="MinuteNum" name="MinuteNum" value="@techTypeList[i - 1].MinuteNum" data-des="设备产量/分钟" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">检验产量/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="ExamineNum" name="ExamineNum" value="@techTypeList[i - 1].ExamineNum" data-des="检验产量/分钟" required />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                    </div>
                                }
                            }
                        </div>
                    </div>
                    <div class="box-footer" style="width: 80%; margin-left: 20px;">
                        <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">保存</a>
                        <a role="button" href="@Url.Action("Equipment", "Technology")" class=" btn btn-primary submitbtn">返回</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

<style>
    .has-error {
        border-color: #dd4b39;
        box-shadow: none;
    }
</style>


@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    postData.Data = getParam();
                    //postData.EquipmentId = $("#EquipmentId").val();
                    //postData.sign = $("#sign").val();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("Equipment", "Technology")';
                        }
                    });
                }
            });


            //var yy = document.getElementById("modalData").value;
            //alert(yy.length);

        });

        function formsubmit(t) {
            $("#frmedit").submit();
        }

        $(".okeydown").on("keyup", function () {
            var value = $(this).val();
            if (isNaN(value) || value == "" || value == "Infinity" || value == "NaN") {
                $(this).addClass("has-error");
            } else {
                $(this).removeClass("has-error");
            }
        });


        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        function getParam() {
            var postdata = [];
            $("#all-content").find('.json-content').each(function (r, i) {
                var postdataItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var id = $this.attr('id');
                    var value = $this.val();
                    if (value == "") {
                        value = "0";
                    }
                    postdataItem[id] = value;
                });
                postdata.push(postdataItem);
            });
            //return postdata;
            return JSON.stringify(postdata);
        }
    </script>
}


